package org.itzf.service.impl;

import org.itzf.mapper.CategoryMapper;
import org.itzf.pojo.Category;
import org.itzf.service.CategoryService;
import org.itzf.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {

        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());

        categoryMapper.add(category);
    }

    @Override
    public List<Category> list() {
        Integer userid = ThreadLocalUtil.getUserId();
        return categoryMapper.list(userid);
    }

    @Override
    public Category detail(Integer id) {
        return categoryMapper.detail(id);
    }

    @Override
    public void update(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.update(category);
    }

}
